import time
import traceback

from selenium import webdriver

from .Button import Button
from ..common.ui.Selector import Selector
import pytest

from .Tree import Tree


def test_standard_select():
    browser = webdriver.Chrome()
    browser.maximize_window()
    browser.get("https://fish.iwhalecloud.com/fish-desktop/examples/tree/index.html")
    time.sleep(2)
    try:
        standard_tree_html = Button(browser, 'core\\/standardData.html', Selector.ID)
        standard_tree_html.click()
        time.sleep(0.1)
        standard_tree = Tree(browser, 'treeDemo', Selector.ID)
        standard_tree.select('父节点2 - 展开', '父节点21 - 展开', '叶子节点214')
    finally:
        browser.close()


def test_standard_select_root_node():
    browser = webdriver.Chrome()
    browser.maximize_window()
    browser.get("https://fish.iwhalecloud.com/fish-desktop/examples/tree/index.html")
    time.sleep(2)
    try:
        standard_tree_html = Button(browser, 'core\\/standardData.html', Selector.ID)
        standard_tree_html.click()
        time.sleep(0.1)
        standard_tree = Tree(browser, 'treeDemo', Selector.ID)
        standard_tree.select('父节点2 - 展开', '父节点21 - 展开')
    finally:
        browser.close()

def test_simple_select():
    browser = webdriver.Chrome()
    browser.maximize_window()
    browser.get("https://fish.iwhalecloud.com/fish-desktop/examples/tree/index.html")
    time.sleep(2)
    try:
        simple_tree_html = Button(browser, 'core\\/simpleData.html', Selector.ID)
        simple_tree_html.click()
        time.sleep(2)
        simple_tree = Tree(browser, 'treeDemo', Selector.ID)
        simple_tree.select('cems v8.0', 'Connection', 'Product Catalog', 'HDFS Connection', '10.45.190.12 HDFS')
    # except:
    #     traceback.print_exc()
    finally:
        browser.close()


if __name__ == '__main__':
    pytest.main(['-s', 'Tree_test.py'])
